<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class List_city_model extends CI_Model
{

    public function getListCity()
    {
        $return = array();
        $this->db->select("id, name");
        $this->db->from('list_city');
        $this->db->where(array(
            'delete_flag'    =>  '0'
        ));
        $rs = $this->db->get();
        if ($rs->num_rows() > 0) {
            $return = $rs->result_array();
            $rs->free_result();
            return $return;
        } else {
            $rs->free_result();
            return false;
        }
    }
    public function getCategoryInfo($catId, $langCode)
    {
        $return = array();
        $this->db->select("id, parent_id, name_$langCode as 'name', href");
        $this->db->from('category');
        $this->db->where(array(
            'id'    =>  $catId,
            'status'    =>  '1'
        ));
        $rs = $this->db->get();
        if ($rs->num_rows() > 0) {
            $return = $rs->result_array();
            $rs->free_result();
            return $return;
        } else {
            $rs->free_result();
            return false;
        }
    }
    
    public function getParentCategory($langCode,$status = true)
    {
        $return = array();
        $this->db->select("id, parent_id, name_$langCode as 'name', href");
        $this->db->from('category');
        if ($status) {
            $this->db->where(array(
                'parent_id' => '0',
                'status' => '1'
            ));
        } else {
            $this->db->where(array(
                'parent_id' => '0'
            ));
        }
        $rs = $this->db->get();
        $return = $rs->result_array();
        $rs->free_result();
        return $return;
    }

    public function getChildrenCategory($parentId,$langCode,$status = true)
    {
        $return = array();
        $this->db->select("id, parent_id, name_$langCode as 'name', href");
        $this->db->from('category');
        if ($status) {
            $this->db->where(array(
                'parent_id' => $parentId,
                'status' => '1'
            ));
        } else {
            $this->db->where(array(
                'parent_id' => $parentId
            ));
        }
        $rs = $this->db->get();
        if ($rs->num_rows() > 0) {
            $return = $rs->result_array();
            $rs->free_result();
            return $return;
        } else {
            $rs->free_result();
            return false;
        }
    }
    public function getListSimByNetworkId($id, $numPost = '', $start = '')
    {
    $return = array();
    $this->db->select("id, phone, list_city_id, list_group_id, list_network_id, price ");
    $this->db->from('item_sim');
    $this->db->where(array(
    		'delete_flag'    =>  0,
    		'list_network_id' => $id
    ));
    
    $this->db->order_by('modified', 'desc');
    //if($numPost != '' || $start != '')
    	//$this->db->limit($numPost, $start);
    $rs = $this->db->get();
    $return = $rs->result_array();
    $rs->free_result();
    return $return;
    }

}

?>
